package 实战.猎头问题;

import com.sun.org.apache.regexp.internal.RE;
import 数据结构.SkipList;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;

public class LieTouXiTong {

    private Long id = 0L;

    private HashMap<Long,LieTou> map = new HashMap<>();

    //猎头类
    private static class LieTou{

        private String name;

        private Long id;

        private Long integral;

        public LieTou(String name, Long id, Long integral) {
            this.name = name;
            this.id = id;
            this.integral = integral;
        }
        public void setIntegral(Long integral) {
            this.integral = integral;
        }
    }

    //跳表类
    private static class SkipList{

        private final static int MAX_LEVEL = 32;

        private final static Double p = 0.25;

        private static int curLevel = 0;

        private Node head = new Node(MAX_LEVEL + 1);

        private Random r = new Random();

        public void printAll_beautiful(){
            if (curLevel == 0){
                System.out.println("the SkipList is null");
            }
            Node p  = head;
            Node[] c = p.forwards;
            for (int i = curLevel; i > 0; i--) {
                Node cur = c[i];
                while (cur != null && cur.forwards[i] != null){
                    System.out.print(cur.data);
                }
            }

        }





        private static class Node{
            private int data = -1;

            private Node[] forwards;

            public Node(int level) {
                forwards = new Node[level + 1];
            }

            @Override
            public String toString() {
                StringBuilder builder = new StringBuilder();
                builder.append("{ data: ");
                builder.append(data);
                builder.append(" }");
                return builder.toString();
            }
        }
    }

    public Long addLieTou(String name){
        map.put(id++,new LieTou(name,id ,0L ) );
        return id;
    }

    public LieTou getLieTouById(Long id){
        return map.get(id);
    }

    public void deleteLieTouById(Long id){
        map.remove(id);
    }

    public void updateLieTouById(Long id,Long integral){
        LieTou lieTou = map.get(id);
        if (lieTou == null){
            throw new RuntimeException("该id没有用户");
        }
        lieTou.setIntegral(integral);
        map.put(id,lieTou );
    }












}
